package jin.si.util;

import org.apache.commons.lang3.RandomStringUtils;

import java.util.Random;

/**
 * @projectName: siyun_springboot
 * @package: si.yun.util
 * @className: RandomUtil
 * @date: 2022/1/5 13:46:15
 * @author: LBF
 */
public class RandomUtil {
    //产生验证码
    public static String randomCode() {
        String verifyCode = RandomStringUtils.randomNumeric(6);
        return verifyCode;
    }

    //产生订单号
    public static String getOrderTo() {
        String orderTo = RandomStringUtils.randomNumeric(22);
        return orderTo;
    }

    /**
     * 生成n位随机数字和字母
     * @param n 随机字符的位数
     * @return n位数字和字母组成的随机字符串
     */
    public static String getRandomCharStr(int n) {
        String codes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        Random random = new Random();
        StringBuilder randomStr = new StringBuilder();
        for (int i = 0; i < n; i++) {
            randomStr.append(codes.charAt(random.nextInt(62)));
        }
        return randomStr.toString();
    }
}
